(C) 1996 AROS - The Amiga Replacement OS


NAME
LONG IEEESPSqrt()
SYNOPSIS

LONG y

LOCATION
In MathIeeeSingTransBase at offset 16
FUNCTION
Calculate square root of IEEE single precision number

INPUTS
y
IEEE single precision number
RESULT
IEEE single precision number

flags: zero : result is zero negative : 0 overflow : square root could not be calculated

NOTES
EXAMPLE
BUGS
SEE ALSO
INTERNALS
ALGORITHM: First check for a zero and a negative argument and take appropriate action. y = M * 2^E

Exponent is an odd number: y = ( M*2 ) * 2^ (E-1) Now E' = E-1 is an even number and -> sqrt(y) = sqrt(M) * sqrt(2) * sqrt (2^E') = sqrt(M) * sqrt(2) * 2^(E'/2) (with sqrt(M*2)>1) = sqrt(M) * sqrt(2) * 2^(E'/2) = sqrt(M) * 1/sqrt(2) * 2^(1+(E'/2)) = sqrt(M/2) * 2^(1+(E'/2))

Exponent is an even number: -> sqrt(y) = sqrt(M) * sqrt (2^E) = = sqrt(M) * 2^(E/2)

Now calculate the square root of the mantisse. The following algorithm calculates the square of a number + delta and compares it to the mantisse. If the square of that number + delta is less than the mantisse then keep that number + delta. Otherwise calculate a lower offset and try again. Start out with number = 0;

Exponent = -1; Root = 0; repeat { if ( (Root + 2^Exponent)^2 < Mantisse) Root += 2^Exponent Exponent --; } until you`re happy with the accuracy

HISTORY
23.07.1997 bergers
Initial revision
21.07.1997 bergers
*** empty log message ***